import { GetServerSideProps, NextPage, PageConfig } from 'next';
import Head from 'next/head';
import { tbteam } from '../../../atoms/db';
import Content from './content';
import { Query as Q1 } from '../../api/project/content/query.api';


interface IProps {
	query: Q1;
	team: ITbteam;
}

/**
 * 项目管理
 */
const Page: NextPage<IProps> = ({ query, team }) => {
	return (
		<>
			<Head>
				<title>项目管理</title>
				<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"></link>
				<link rel="icon" type="image/x-icon" sizes="32x32" href="/favicon-32x32.ico" ></link>
				<link rel="icon" type="image/x-icon" sizes="16x16" href="/favicon-16x16.ico"></link>
			</Head>
			<Content initialquery={query} team={team} />
		</>
	);
};

export const config: PageConfig = {
	amp: false
};

export default Page;

// pre-render this page on each request
export const getServerSideProps: GetServerSideProps<IProps> = async (context) => {
	const query = context.query as Record<string, string>;
	const team_id = context.query.id as string;
	const data = await tbteam()
		.first('*')
		.where({
			team_id
		});
	return {
		props: {
			query: {
				page: query.page || '1',
				pagesize: '10',
				q: query.q || '',
				team_id
			},
			team: data
		}
	};
};
